begin
  require 'tinder'
rescue LoadError
  raise "Could not require 'tinder.'  Try installing the tinder gem."
end

class CampfireBackup < Backup
  attr_meta :subdomain, :use_ssl, :username, :password

  def run
    campfire = Tinder::Campfire.new(self.subdomain, { :ssl => (self.use_ssl || false) })
    campfire.login(self.username, self.password)

    transcripts = []

    campfire.rooms.each do |room|
      (room.available_transcripts || []).each do |t|
        transcripts << room.transcript(t)
      end
    end

    write 'campfire.xml', transcripts.flatten.to_xml
  rescue => e
    y e
  ensure
    campfire.logout
  end
end
